function submitForm(pageName)
{ 
	var xhr; 
	try {  xhr = new ActiveXObject('Msxml2.XMLHTTP');   }
	catch (e) 
	{
	try {   xhr = new ActiveXObject('Microsoft.XMLHTTP'); }
	catch (e2) 
	{
	   try {  xhr = new XMLHttpRequest();  }
	   catch (e3) {  xhr = false;   }
	 }
	}

	xhr.onreadystatechange  = function() 
	{ 
	    if(xhr.readyState  == 4)
	    {
		main = document.getElementById('main');
		if(xhr.status  == 200) 
		    main.innerHTML=xhr.responseText;
		else 
		    main.innerHTML=xhr.status;
	    }
	}

	xhr.onreadystatechange = function ()
	{
	    if (this.readyState == 4 && this.status == 200)
	    {
		var e = document.getElementById('main');
		e.innerHTML = xhr.responseText;
		var scripts = e.getElementsByTagName('script');
		for(var i=0; i < scripts.length;i++)
		{
		    if (window.execScript)
		    {
			window.execScript(scripts[i].text.replace('<!--',''));
		    }
		    else
		    {
			window.eval(scripts[i].text);
		    }
		}
	    }
	}

    if (pageName == 'search')
    {
	/* looking for something ? :) */
	var pattern = escape(document.searchForm.searchinput.value);
	var params = "search=" + pattern;

	xhr.open('POST', pageName, true);
	xhr.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
	xhr.send(params);
    }
    else if (pageName == 'post')
    {
	/* post a new article */
	var title = document.editform.title.value;
	var text = escape(CKEDITOR.instances.editor1.getData());
	var params = "title=" + title + "&text=" + text;

	xhr.open('POST', pageName, true);
	xhr.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
	xhr.send(params);
    }
    else if (pageName == 'editpost')
    {
	/* edit article */
	var form = document.getElementsByName('editform')[0];
	var title = encodeURIComponent(form.title.value);
	var text = encodeURIComponent(CKEDITOR.instances.editor1.getData());
	var params = "title=" + title + "&text=" + text;

	xhr.open('POST', pageName, true);
	xhr.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
	xhr.send(params);
    }
    else
    {
	xhr.open( "GET", pageName,  true);
	xhr.send(null);
    }
}
